import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { RedisModule } from '@nestjs-modules/ioredis';
import { JwtModule } from '@nestjs/jwt';
import { ConfigService } from '@nestjs/config';
import { NovelController } from './novel.controller';
import { NovelService } from './novel.service';
import { NovelChapterService } from './novel-chapter.service';
import { NovelCrawlerService } from './services/novel-crawler.service';
import { NovelTaskService } from './services/novel-task.service';
import { TaskRecoveryService } from './services/task-recovery.service';
import { FanqieCrawler } from './services/fanqie-crawler.service';
import { ImportNovelService } from './services/import-novel.service';
import { CategoryModule } from '../category/category.module';
import { InteractionController } from './interaction.controller';
import { ProfileController } from './profile.controller';
import { ImportController } from './controllers/import.controller';
import { InteractionService } from './interaction.service';
import { ProfileService } from './profile.service';
import { Novel } from './entities/novel.entity';
import { NovelChapter } from './entities/novel-chapter.entity';
import { NovelParseTask } from './entities/novel-parse-task.entity';
import { MasterCategory } from './entities/master-category.entity';
import { SiteCategoryMap } from './entities/site-category-map.entity';
import { UserFavorite } from './entities/user-favorite.entity';
import { UserReadingHistory } from './entities/user-reading-history.entity';
import { Comment } from './entities/comment.entity';
import { Bookshelf } from './entities/bookshelf.entity';
import { User } from '../user/entities/user.entity';
import { UserModule } from '../user/user.module';
import { QueueModule } from '../queue/queue.module';

@Module({
  imports: [
    TypeOrmModule.forFeature([
      Novel,
      NovelChapter,
      NovelParseTask,
      MasterCategory,
      SiteCategoryMap,
      UserFavorite,
      UserReadingHistory,
      Comment,
      Bookshelf,
      User,
    ]),
    UserModule,
    QueueModule,
    CategoryModule,
    JwtModule.registerAsync({
      useFactory: (configService: ConfigService) => ({
        secret:
          configService.get<string>('jwt.accessSecret') || 'access-secret-key',
        signOptions: {
          expiresIn: configService.get<string>('jwt.accessExpiresIn') || '15m',
        },
      }),
      inject: [ConfigService],
    }),
    RedisModule.forRootAsync({
      useFactory: () => ({
        type: 'single',
        options: {
          host: '124.222.38.18',
          port: 6379,
          password: 'q13812833598',
        },
      }),
    }),
  ],
  controllers: [
    NovelController,
    InteractionController,
    ProfileController,
    ImportController,
  ],
  providers: [
    NovelService,
    NovelChapterService,
    NovelCrawlerService,
    NovelTaskService,
    TaskRecoveryService,
    FanqieCrawler,
    ImportNovelService,
    InteractionService,
    ProfileService,
  ],
  exports: [
    NovelService,
    NovelChapterService,
    InteractionService,
    ProfileService,
  ],
})
export class NovelModule {}
